Bitset - A collection of bits. More...
#include <fbitset.h>
Public Types | |
enum | ReturnTypes { kEmptySize = -2L, kBitNotFound = -1L } |
Public Member Functions | |
BitSet () | |
Default constructor (size is 0). | |
BitSet (uint32 size) | |
Constructor with a given size (number of wanted bits). | |
BitSet (const BitSet &) | |
Copy constructor. | |
virtual | ~BitSet () |
Virtual destructor. | |
BitSet & | operator= (const BitSet &) |
Assignment operator. | |
bool | operator== (const BitSet &) |
The equality operator. | |
bool | operator!= (const BitSet &) |
The inequality operator. | |
BitSet & | operator&= (const BitSet &toAnd) |
Bitwise and (AND), both bitsets needs to have the same size, otherwise nothing happens. | |
BitSet & | operator|= (const BitSet &toOr) |
Bitwise inclusive or (OR), both bitsets needs to have the same size, otherwise nothing happens. | |
BitSet & | operator^= (const BitSet &toXOr) |
Bitwise exclusive or (XOR), both bitsets needs to have the same size, otherwise nothing happens. | |
void | setSize (uint32 size) |
Resize to then number of bits that the bitset can hold, resize to 0 is allowed (free all), allocate memory is rounded to next kChunkSize. | |
uint32 | getSize () const |
Return the current size of the BitSet. | |
void | setBit (uint32 which) |
Sets the bit (at 'which' position) to 1; resizes the bitSet if necessary when which > size. | |
void | clearBit (uint32 which) |
Sets the bit (at 'which' position) to 0; resizes the bitSet if necessary when which > size. | |
void | toggleBit (uint32 which) |
Changes the bits value (flip: 0=>1, 1=>0); resizes the bitSet if necessary when which > size. | |
void | setAll () |
Sets all bits to 1. | |
void | clearAll () |
Sets all bits to 0 (clears every bit). | |
bool | getBit (uint32 which) const |
Returns if the bit (at 'which' position) is set to 1. | |
bool | isEmpty () const |
Returns true, if no bit is set (all 0). | |
uint32 | countSetBits (int32 toPos=-1) const |
Return the count of set bits from 0 to toPos position. | |
int64 | getFirstSet () const |
Return the first found set bit (from 0 to size-1) or see ReturnTypes. | |
int64 | getFirstNotSet () const |
Return the first found NOT set bit (from 0 to size-1) or see ReturnTypes. | |
int64 | getLastSet () const |
Return the last found set bit (from size-1 to 0) or see ReturnTypes. | |
Protected Types | |
typedef uint32 | BSChunkType |
Protected Member Functions | |
virtual void | onChange () |
is called when bits are changed, derived classes can overwrite this. | |
uint32 | getChunkCount () const |
Return the count of chunk currently used and allocate. | |
BSChunkType | getChunk (uint32 n) const |
Return the wanted chunk by index (return 0 if not available). | |
void | setChunk (uint32 n, BSChunkType chunk) |
Set/replace a given chunk. | |
Static Protected Attributes | |
static const uint32 | kChunkSize = sizeof (BSChunkType) * 8 |
static const uint32 | kChunkByteSize = sizeof (BSChunkType) |
static const BSChunkType | kFullChunk = 0xfffffffful |
Bitset - A collection of bits.
Individual indexed bits can be examined, set, or cleared. Its size is variable (grows as needed). One BitSet may be used to modify the contents of another BitSet through logical AND, logical inclusive OR, and logical exclusive OR operations. By default, all bits in the set initially have the value 0 (Not Set).
0 AND 0 = 0 0 OR 0 = 0 0 XOR 0 = 0 0 AND 1 = 0 0 OR 1 = 1 0 XOR 1 = 1 1 AND 0 = 0 1 OR 0 = 1 1 XOR 0 = 1 1 AND 1 = 1 1 OR 1 = 1 1 XOR 1 = 0
typedef uint32 BSChunkType [protected] |
enum ReturnTypes |
BitSet | ( | ) |
Default constructor (size is 0).
BitSet | ( | uint32 | size | ) |
Constructor with a given size (number of wanted bits).
~BitSet | ( | ) | [virtual] |
Virtual destructor.
bool operator== | ( | const BitSet & | toCompare | ) |
The equality operator.
bool operator!= | ( | const BitSet & | toCompare | ) |
The inequality operator.
Bitwise and (AND), both bitsets needs to have the same size, otherwise nothing happens.
Bitwise inclusive or (OR), both bitsets needs to have the same size, otherwise nothing happens.
Bitwise exclusive or (XOR), both bitsets needs to have the same size, otherwise nothing happens.
void setSize | ( | uint32 | size | ) |
Resize to then number of bits that the bitset can hold, resize to 0 is allowed (free all), allocate memory is rounded to next kChunkSize.
uint32 getSize | ( | ) | const [inline] |
Return the current size of the BitSet.
void setBit | ( | uint32 | which | ) |
Sets the bit (at 'which' position) to 1; resizes the bitSet if necessary when which > size.
void clearBit | ( | uint32 | which | ) |
Sets the bit (at 'which' position) to 0; resizes the bitSet if necessary when which > size.
void toggleBit | ( | uint32 | which | ) |
Changes the bits value (flip: 0=>1, 1=>0); resizes the bitSet if necessary when which > size.
void setAll | ( | ) |
Sets all bits to 1.
void clearAll | ( | ) |
Sets all bits to 0 (clears every bit).
bool getBit | ( | uint32 | which | ) | const |
Returns if the bit (at 'which' position) is set to 1.
bool isEmpty | ( | ) | const |
Returns true, if no bit is set (all 0).
uint32 countSetBits | ( | int32 | toPos = -1 |
) | const |
Return the count of set bits from 0 to toPos position.
int64 getFirstSet | ( | ) | const |
Return the first found set bit (from 0 to size-1) or see ReturnTypes.
int64 getFirstNotSet | ( | ) | const |
Return the first found NOT set bit (from 0 to size-1) or see ReturnTypes.
int64 getLastSet | ( | ) | const |
Return the last found set bit (from size-1 to 0) or see ReturnTypes.
virtual void onChange | ( | ) | [inline, protected, virtual] |
is called when bits are changed, derived classes can overwrite this.
uint32 getChunkCount | ( | ) | const [inline, protected] |
Return the count of chunk currently used and allocate.
BitSet::BSChunkType getChunk | ( | uint32 | n | ) | const [protected] |
Return the wanted chunk by index (return 0 if not available).
void setChunk | ( | uint32 | n, | |
BitSet::BSChunkType | chunk | |||
) | [protected] |
Set/replace a given chunk.
const uint32 kChunkSize = sizeof (BSChunkType) * 8 [static, protected] |
const uint32 kChunkByteSize = sizeof (BSChunkType) [static, protected] |
const BSChunkType kFullChunk = 0xfffffffful [static, protected] |